package com.lx.algorithm.Tree;

import java.util.List;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-10-20 14:26:14
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-10-20     张李鑫                     1.0         1.0 Version
 */
public class MaxHappy {
    public static class Node {
        public int happy;
        public List<Node> list;

        public Node(int happy, List<Node> list) {
            this.happy = happy;
            this.list = list;
        }
    }

    public static class Info {
        public int max;


        public Info(int max) {
            this.max = max;
        }
    }


    public static int happy(Node node) {
        return process(node).max;
    }

    public static Info process(Node node) {
        if (node == null) {
            return new Info(0);
        }
        List<Node> list = node.list;
        int max = 0;
        for (int i = 0; i < list.size(); i++) {
            Info leftInfo = process(list.get(i));
            max += leftInfo.max;
        }
        return new Info(max);
    }


}
